package interfazUsuario.main;

import interfazUsuario.botones.Boton;
import interfazUsuario.botones.BotonAbstract;
import interfazUsuario.botones.BotonExpListaBoton;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import utilsPc.listas.ListaBotonPc;
import utilsPc.listas.ListaUsuarioPc;

import cultivameCore.motor.Accion;
import cultivameCore.motor.Refrescable;
import cultivameCore.motor.threads.InterfacesThread;
import cultivameCore.geometria.Punto;

@SuppressWarnings("serial")
public class MainIU extends JPanel implements Refrescable {
	
	private ListaBotonPc lista=new ListaBotonPc();
	private ImageIcon fondo;
	private int puntero=0;
	private InterfacesThread interfacesThread;
	private ListaUsuarioPc listaUsr=null;
	
	public MainIU(InterfacesThread threadInterface) {
		 setMinimumSize(new Dimension(450, 300));
		 addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				Punto p=new Punto(arg0.getPoint().x,arg0.getPoint().y);
				BotonAbstract b=lista.getSelectedBoton(p);
				if (b!=null){
					b.click();
				}
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		// Cargo imagen de Fondo
		this.interfacesThread = threadInterface;
		// fondo=Image.createImage("");
		ImageIcon img = new ImageIcon(getClass().getResource(
				"/interfazUsuario/imagenes/medidores/medidorTmp.png"));
		BotonExpListaBoton jugar = new BotonExpListaBoton(new Punto(50, 50),
				img);
		Boton jugar2 = new Boton(new Punto(50, 100), img);
		jugar2.setAccion(new Accion() {
			public void action() {
				// EntornoIU pe=new EntornoIU(display,interfacesThread);
				// display.setCurrent(MainMidlet.pantallaEntorno);
				System.out.println("act00");
			}
		});
		jugar.add(jugar2);
		lista.add(jugar);
		jugar2 = new Boton(new Punto(50, 100), img);
		jugar2.setAccion(new Accion() {
			public void action() {
				// EntornoIU pe=new EntornoIU(display,interfacesThread);
				// display.setCurrent(MainMidlet.pantallaEntorno);
				System.out.println("act1");
			}
		});
		lista.add(jugar2);
	}
	
	public InterfacesThread getInterfacesThread() {
		return interfacesThread;
	}

	public void setInterfacesThread(InterfacesThread interfacesThread) {
		this.interfacesThread = interfacesThread;
	}

	public void paint(Graphics g){
		g.setColor(Color.white);
		g.fillRect(0, 0, getWidth(), getHeight());
		//pintar botones
		for(int i=0;i<lista.length();i++){
			lista.get(i).drawme(g);
		}
		BotonAbstract botSelect=lista.getSelectedBoton(puntero);
		g.setColor(Color.yellow);
		g.drawRect((int)botSelect.getPunto().getX(),(int)botSelect.getPunto().getY(),
				botSelect.getImg().getIconWidth(), botSelect.getImg().getIconHeight());
	}
	
	public void actualizar(int ms) {
		// TODO Auto-generated method stub
		repaint();
	}
}
